<#import "../../../config/config.ftl" as config />
<#import "../../../template/template.ftl" as template />

<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <title>角色管理</title>

<@config.humaneCSS></@config.humaneCSS>
<@config.gcss></@config.gcss>
<@config.bootCSS></@config.bootCSS>
<@config.wavesCSS></@config.wavesCSS>
<@config.animateCSS></@config.animateCSS>
<@config.styleCSS></@config.styleCSS>
<@config.themesCSS></@config.themesCSS>
<@config.bootTableCSS></@config.bootTableCSS>
<@config.appCSS></@config.appCSS>
<@config.sweetalertCSS></@config.sweetalertCSS>
</head>
<body class="">
<@template.pageLoad></@template.pageLoad>
<div class="overlay"></div>
<@template.topBar></@template.topBar>
<section>

<@template.leftSidebar flag="role"></@template.leftSidebar>
    <@template.rightSidebar></@template.rightSidebar>
</section>
<section class="content">
    <div class="container-fluid">
        <div id="toolbar">
            <button type="button" class="btn btn-info waves-effect" onclick="doAdd();">新增</button>
        </div>
        <table id="roleInfo">
        </table>
    </div>
</section>
<div class="modal fade middle-modal" id="roleModal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="defaultModalLabel">角色新增</h4>
            </div>
            <div class="modal-body">
                <div class="row clearfix">
                    <form id="roleForm" method="POST">
                        <div class="col-sm-6">
                            <div class="form-group">
                                <div class="form-line">
                                    <input type="text" class="form-control" placeholder="角色名称" name="name" id="name"
                                           required/>
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-6">
                            <div class="form-group">
                                <div class="form-line">
                                    <input type="text" class="form-control" placeholder="code" name="code" id="code"
                                           required/>
                                </div>
                            </div>
                        </div>

                        <div class="col-sm-6">
                            <div class="form-group">
                                <div class="form-line">
                                    <input type="text" class="form-control" placeholder="描述" name="des"
                                           id="des" required/>
                                </div>
                            </div>
                        </div>

                        <input type="hidden" name="id" value="0" id="id">
                    </form>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-link waves-effect" id="exec" onclick="doExec();">保存</button>
                <button type="button" class="btn btn-link waves-effect" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>

<@template.footer></@template.footer>
<@config.jqueryJS></@config.jqueryJS>
<@config.jquerySerializeJsonJS></@config.jquerySerializeJsonJS>
<@config.bootJS></@config.bootJS>
<@config.jqueryFormJS></@config.jqueryFormJS>
<@config.bootSelectJS></@config.bootSelectJS>
<@config.jquerySrollJS></@config.jquerySrollJS>
<@config.bootTableJS></@config.bootTableJS>
<@config.wavesJS></@config.wavesJS>
<@config.laydateJS></@config.laydateJS>
<@config.jqueryCountToJs></@config.jqueryCountToJs>
<@config.jqueryValidateJS></@config.jqueryValidateJS>
<@config.humaneJS></@config.humaneJS>
<@config.sweetalertJS></@config.sweetalertJS>
<@config.adminJS></@config.adminJS>
<@config.demoJS></@config.demoJS>
<@config.appJS></@config.appJS>


<script type="application/javascript">
    var validator
    $(function () {
        $.App.home.loadPage({
            id: "roleInfo",
            url: '${base}/sys/role/loadpage.json',
            columns: [
                {field: "name", title: "角色名称"},
                {field: "code", title: "角色编码"},
                {field: "updateTimeStr", title: "修改时间"},
                {
                    field: "id", title: "操作", formatter: function (value, row, index) {
                    var btn = "";
                    return btn;
                }
                }
            ],
            toolbar: "#toolbar",
            queryParams: function (params) {
                var obj = {
                    order: params.order,
                    offset: params.offset,
                    limit: params.limit
                };
                return obj;
            }
        });
        validator = $.App.home.validateForm("roleForm");
        $('#roleForm').on('hide.bs.modal', function () {
            $("#id").val(0);
            $.App.home.clearFormData("roleForm");
        })
    });

    function doAdd() {
        $("#roleModal").modal();
    }

    function doExec() {
        var valid = $("#roleForm").valid();
        if (!valid) {
            return;
        }
        var id = $("#id").val();
        var url = "";
        if ("0" == id) {   //新增
            url = "${base}/sys/role/add.json";
        } else {
            url = "${base}/sys/role/update.json";
        }
        $("#roleForm").ajaxSubmit({
            url: url,
            type: "post",
            success: function (resp) {
                if (resp.code == 200) {
                    $('#roleModal').modal('hide')
                    $.App.home.topMessage("success", "操作成功");
                    $.App.home.clearFormData("roleForm")
                    $.App.home.reloadTable("roleInfo");
                    initMenuStep();
                } else {
                    $.App.home.topMessage("error", resp.msg);
                }
            },
            error: function (resp) {
                $.App.home.topMessage("error", JSON.stringify(resp));
            }
        });
    }

    function doRemove(code) {
        $.App.home.showConfirmMessage("确定要删除菜单吗？改菜单关联的子菜单都会被删除", deleteByCode, code);
    }

    function doEdit(id) {
        $.ajax({
            url: '${base}/sys/role/getrolebyid.json',
            data: {id: id},
            success: function (resp) {
                if (resp.code == 200) {
                    doEditView(resp.data);
                } else {
                    $.App.home.showErrorMessage();
                }
            },
            error: function () {
                $.App.home.showErrorMessage()
            }
        });
    }

    /**
     * 插入修改的信息
     * @param data
     */
    function doEditView(data) {
        $("#name").val(data.name);
        $("#code").val(data.code);
        $("#des").val(data.des);
        $("#id").val(data.id);
        $("#roleModal").modal();
    }



    function deleteByCode(id) {
        $.ajax({
            url: "${base}/sys/role/deleterolebyid.json",
            data: {id: id},
            success: function (resp) {
                if (resp.code == 200) {
                    $.App.home.showSuccessMessage();
                    $.App.home.reloadTable("roleInfo");
                } else {
                    $.App.home.showErrorMessage();
                }
            },
            error: function () {
                $.App.home.showErrorMessage();
            }
        });
    }












</script>


</body>
        